package com.chinasofti.manager.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.chinasofti.common.IdWorker;
import com.chinasofti.dao.DeptRepository;
import com.chinasofti.dao.EmpRepository;
import com.chinasofti.dao.OccupationApplicationRepository;
import com.chinasofti.manager.service.EmpApplyService;
import com.chinasofti.model.Dept;
import com.chinasofti.model.Emp;
import com.chinasofti.model.OccupationApplication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Creator: <br>
 * Date: <br>
 * Description: <br>
 */
@Service
@Component
public class EmpApplyServiceImpl implements EmpApplyService {
    @Autowired
    private IdWorker idWorker;
    @Autowired
    private EmpRepository empRepository;
    @Autowired
    private DeptRepository deptRepository;
    @Autowired
    private OccupationApplicationRepository occupationApplicationRepository;

    @Override
    public void commitApply(String name, String targetDept) {
        Emp emp = empRepository.findByName(name);
        OccupationApplication apply = new OccupationApplication();
        apply.setId(idWorker.nextId());
        apply.setName(emp.getName());
        apply.setOriginDept(emp.getDeptName());
        apply.setTargetDept(targetDept);
        apply.setState(2);
        occupationApplicationRepository.save(apply);
    }

    @Override
    public List<Dept> queryDepts() {
        return deptRepository.findAll();
    }

}
